package com.example.mybaseapp.ui

import android.os.Bundle
import android.widget.FrameLayout
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.mybaseapp.R
import com.example.mybaseapp.ui.fragment.recommand.PaletteRecommandFragment

class FragmentTestActivity : AppCompatActivity() {
    private val fragmentTest = PaletteRecommandFragment.newInstance()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_fragment_test)
        initFragment()
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
    }

    private fun initFragment() {
        findViewById<FrameLayout>(R.id.fragmentLayout).apply {
            supportFragmentManager.beginTransaction().apply {
                if(!fragmentTest.isAdded){
                    add(R.id.fragmentLayout, fragmentTest)
                }else{
                    show(fragmentTest)
                }
                commit()
            }
        }
    }
}